/*
 * ----------------------------------------------------------------------------
 * File Name: adder(CLA_32bit ver)
 * Author: Aeriff
 * Date Created: 2025.3.4
 * Last Modified: 2025.3.4
 * Description: A 32-bit Carry Lookahead Adder, consists of eight 4-bit CLA
 * ----------------------------------------------------------------------------
*/

`timescale 1ns / 1ps

module adder(
    input  [31:0] operand1,
    input  [31:0] operand2,
    input         cin,
    output [31:0] result,
    output        cout
    );
    // assign {cout,result} = operand1 + operand2 + cin;

    wire [7:0] inner_cout;

    CLA_4bit CLA0 (
        .A(operand1[3:0]),
        .B(operand2[3:0]),
        .Cin(cin),
        
        .Sum(result[3:0]),
        .Cout(inner_cout[0])
    );

    CLA_4bit CLA1 (
        .A(operand1[7:4]),
        .B(operand2[7:4]),
        .Cin(inner_cout[0]),
        
        .Sum(result[7:4]),
        .Cout(inner_cout[1])
    );

    CLA_4bit CLA2 (
        .A(operand1[11:8]),
        .B(operand2[11:8]),
        .Cin(inner_cout[1]),
        
        .Sum(result[11:8]),
        .Cout(inner_cout[2])
    );

    CLA_4bit CLA3 (
        .A(operand1[15:12]),
        .B(operand2[15:12]),
        .Cin(inner_cout[2]),
        
        .Sum(result[15:12]),
        .Cout(inner_cout[3])
    );

    CLA_4bit CLA4 (
        .A(operand1[19:16]),
        .B(operand2[19:16]),
        .Cin(inner_cout[3]),
        
        .Sum(result[19:16]),
        .Cout(inner_cout[4])
    );

    CLA_4bit CLA5 (
        .A(operand1[23:20]),
        .B(operand2[23:20]),
        .Cin(inner_cout[4]),
        
        .Sum(result[23:20]),
        .Cout(inner_cout[5])
    );

    CLA_4bit CLA6 (
        .A(operand1[27:24]),
        .B(operand2[27:24]),
        .Cin(inner_cout[5]),
        
        .Sum(result[27:24]),
        .Cout(inner_cout[6])
    );

    CLA_4bit CLA7 (
        .A(operand1[31:28]),
        .B(operand2[31:28]),
        .Cin(inner_cout[6]),
        
        .Sum(result[31:28]),
        .Cout(inner_cout[7])
    );

    assign cout = inner_cout[7];

    

endmodule
